package _17_剑指Offer;

import _17_剑指Offer.datastrcute.TreeNode;

public class _26_剑指Offer树的子结构 {

    // 二叉树一个结构
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) return false;
        return isSame(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }

    public boolean isSame(TreeNode A, TreeNode B) {
        if (A == null && B != null) return false;

        // a != null && n == null
        // a == null && b == null
        if (A == null || B == null) return true;

        if (A.val != B.val) return false;
        // a != null && b != null;

        return isSame(A.left, B.left) && isSame(A.right, B.right);
    }

}
